<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
    >
      <el-form-item label="名称" prop="search">
        <el-input
          v-model="queryParams.search"
          placeholder="通过用户ID、昵称、手机号进行模糊搜索"
          clearable
          style="width: 310px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付时间" prop="signTime">
        <el-date-picker
          v-model="queryParams.signTime"
          :default-time="['00:00:00', '23:59:59']"
          value-format="yyyy-MM-dd HH:mm:ss"
          :picker-options="pickerOptions"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >查询</el-button
        >
        <el-button icon="el-icon-refresh" class="delBtn" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :show-search.sync="showSearch"
        :columns="columns"
        @queryTable="getListData"
      />
    </el-row>

    <el-table
      ref="table"
      :key="tableKey"
      v-loading="loading"
      :data="roleList"
      style="margin-top: 20px"
    >
      <el-table-column
        v-if="columns[0].visible"
        key="id"
        label="订单ID"
        prop="id"
        :show-overflow-tooltip="true"
        align="left"
      />
      <el-table-column
        v-if="columns[1].visible"
        key="buyerName"
        label="会员昵称"
        prop="buyerName"
        :show-overflow-tooltip="true"
        align="left"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.buyerName + "-" + scope.row.buyerId }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="columns[2].visible"
        key="buyerMobile"
        label="手机号"
        prop="buyerMobile"
        :show-overflow-tooltip="true"
        align="left"
      />
      <el-table-column
        v-if="columns[3].visible"
        key="sellerName"
        label="推广人"
        prop="sellerName"
        :show-overflow-tooltip="true"
        align="left"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.sellerName">{{
            scope.row.sellerName + "-" + scope.row.promoCode
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="columns[3].visible"
        key="sellerJobId"
        label="推广人职责"
        prop="sellerJobId"
        :show-overflow-tooltip="true"
        align="left"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.sellerJobId == 1">投资人</span>
          <span v-if="scope.row.sellerJobId == 2">店长</span>
          <span v-if="scope.row.sellerJobId == 3">员工</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="columns[3].visible"
        key="shopName"
        label="所属门店"
        prop="shopName"
        :show-overflow-tooltip="true"
        align="left"
      />
      <el-table-column
        v-if="columns[5].visible"
        key="userName"
        label="支付状态"
        prop="userName"
        :show-overflow-tooltip="true"
        align="left"
      >
        <template slot-scope="scope">
          <span class="green" v-if="scope.row.status == 2">已支付</span>
          <span class="red" v-else>未支付</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="columns[4].visible"
        key="payTime"
        label="支付时间"
        align="left"
        prop="payTime"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getListData"
    />
    <drawer-vue :row="row" :drawer="drawer" @handleClose="drawer = false" />
  </div>
</template>

<script>
import { getOrder, handShopData } from "@/api/index";
import drawerVue from "./drawer.vue";
export default {
  name: "ShopManage",
  components: { drawerVue },
  data() {
    return {
      row: {},
      drawer: false,
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: 2,
          label: "已支付",
        },
        {
          value: 1,
          label: "未支付",
        },
      ],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      open: false,
      columns: [
        { key: 0, label: `订单ID`, visible: true },
        { key: 1, label: `会员昵称`, visible: true },
        { key: 2, label: `手机号`, visible: true },
        { key: 3, label: `推广人`, visible: true },
        { key: 4, label: `推广人职责`, visible: true },
        { key: 5, label: `所属门店`, visible: true },
        { key: 6, label: `支付状态`, visible: true },
        { key: 7, label: `支付时间`, visible: true },
      ],
      title: "新增",
      tableKey: 0,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 10,
      // 角色表格数据
      roleList: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        search: "",
        status: "",
        signTime: "",
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getListData();
  },
  methods: {
    /** 查询角色列表 */
    getListData() {
      const data = {
        ...this.queryParams,
        startTime:
          this.queryParams.signTime &&
          new Date(this.queryParams.signTime[0]).getTime(),
        endTime:
          this.queryParams.signTime &&
          new Date(this.queryParams.signTime[1]).getTime(),
      };
      delete data.signTime;
      getOrder(data).then((response) => {
        this.roleList = response.data.records;
        this.total = response.data.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$nextTick(() => {
        this.queryParams.current = 1;
        this.getListData();
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.current = 1;
      this.handleQuery();
    },
  },
};
</script>
<style lang="scss" scoped>
.btnText {
  color: #0052d9 !important;
}
.dialogForm {
  ::v-deep .el-form-item {
    margin-bottom: 10px;
  }
  ::v-deep.el-form--label-top .el-form-item__label {
    padding: 0;
  }
}
.add {
  background: #0052d9;
  color: #fff;
  border: none;
}
.delBtn {
  background: #e7e7e7;
  color: #000;
  border: none;
}
.open {
  width: 52px;
  height: 32px;
  background: #e3f9e9;
  border-radius: 3px 3px 3px 3px;
  border: 1px solid #2ba471;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 400;
  font-size: 14px;
  color: #2ba471;
}
.close {
  width: 52px;
  height: 32px;
  background: #d8d8d8;
  border-radius: 3px 3px 3px 3px;
  border: 1px solid #767676;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 400;
  font-size: 14px;
  color: #767676;
}
.statusBox {
  width: 100%;
  display: flex;
  justify-content: center;
}
.img {
  width: 38px;
  height: 38px;
}
.green {
  color: green;
}
.red {
  color: red;
}
</style>
